﻿/*
 * zarray_unittest.cxx
 *
 *  Created on: 2015年3月4日
 *      Author: Fifi Lyu
 */

#include <gtest/gtest.h>
#include "zpsoe/zalgorithm/zarray.h"
#include <algorithm>

using namespace zpsoe::zalgorithm;

TEST(ZarrayTest, find_string) {
    vector<string> list_;
    list_.push_back("abc");
    list_.push_back("def");
    list_.push_back("ghi");

    EXPECT_TRUE(zarray::find(list_, "def"));
}

TEST(ZarrayTest, find_uint16) {
    vector<uint16_t> list_;
    list_.push_back(10);
    list_.push_back(20);
    list_.push_back(30);

    EXPECT_TRUE(zarray::find(list_, 30));
}

TEST(ZarrayTest, find_uint32) {
    vector<uint32_t> list_;
    list_.push_back(10);
    list_.push_back(20);
    list_.push_back(30);

    EXPECT_TRUE(zarray::find(list_, 30));
}


TEST(ZarrayTest, find_uint64) {
    vector<uint64_t> list_;
    list_.push_back(10);
    list_.push_back(20);
    list_.push_back(30);

    EXPECT_TRUE(zarray::find(list_, 30));
}

TEST(ZarrayTest, find_double) {
    vector<double> list_;
    list_.push_back(10.00);
    list_.push_back(20.00);
    list_.push_back(30.00);

    EXPECT_TRUE(zarray::find(list_, 30.00));
}

TEST(ZarrayTest, find_vector_iterator) {
    vector<string> list_;
    list_.push_back("abc");
    list_.push_back("def");
    list_.push_back("ghi");

    vector<string>::iterator it_;

    EXPECT_TRUE(zarray::find(list_, "def", it_));
    EXPECT_STREQ("def", (*it_).c_str());
}

TEST(ZarrayTest, find_list_iterator) {
    list<string> list_;
    list_.push_back("abc");
    list_.push_back("def");
    list_.push_back("ghi");

    list<string>::iterator it_;

    EXPECT_TRUE(zarray::find(list_, "def", it_));
    EXPECT_STREQ("def", (*it_).c_str());
}


TEST(ZarrayTest, vector_exist) {
    vector<string> list_;
    list_.push_back("abc");
    list_.push_back("def");
    list_.push_back("ghi");

    EXPECT_TRUE(zarray::exist(list_, "ghi"));
}

TEST(ZarrayTest, list_exist) {
    list<string> list_;
    list_.push_back("abc");
    list_.push_back("def");
    list_.push_back("ghi");

    EXPECT_TRUE(zarray::exist(list_, "ghi"));
}

TEST(ZarrayTest, unique_string) {
    vector<string> v_;
    v_.push_back("1");
    v_.push_back("2");
    v_.push_back("3");
    v_.push_back("1");
    v_.push_back("5");
    v_.push_back("3");
    v_.push_back("4");
    v_.push_back("6");
    v_.push_back("4");
    v_.push_back("7");

    vector<string> v2_;
    v2_.push_back("1");
    v2_.push_back("2");
    v2_.push_back("3");
    v2_.push_back("4");
    v2_.push_back("5");
    v2_.push_back("6");
    v2_.push_back("7");

    zarray::unique(v_);

    EXPECT_TRUE(v_ == v2_);
}

TEST(ZarrayTest, unique_int64) {
    vector<int64_t> v_;
    v_.push_back(1);
    v_.push_back(2);
    v_.push_back(3);
    v_.push_back(1);
    v_.push_back(5);
    v_.push_back(3);
    v_.push_back(4);
    v_.push_back(6);
    v_.push_back(4);
    v_.push_back(7);

    vector<int64_t> v2_;
    v2_.push_back(1);
    v2_.push_back(2);
    v2_.push_back(3);
    v2_.push_back(4);
    v2_.push_back(5);
    v2_.push_back(6);
    v2_.push_back(7);

    zarray::unique(v_);

    EXPECT_TRUE(v_ == v2_);
}
